package affcom;

import java.awt.*;

public class Led extends Component
{
  protected volatile boolean allumee;

  private volatile Color colorLed = Color.green;
  private int bordureSize = 1;
  private boolean rounded;
  public Led()
  {
  }

  public void setColorLed(Color colorLed)
  {
     this.colorLed = colorLed;
     repaint();
  }

  public Color getColorLed()
  {
     return colorLed;
  }

  public void setRounded(boolean rounded)
  {
    this.rounded = rounded;
  }
  public boolean isRounded()
  {
    return rounded;
  }

  public void setSelected(boolean allumee)
  {
     this.allumee = allumee;
     Graphics g = getGraphics();
     if (g != null) paint(g);
       else
         repaint();
  }

  public boolean isSelected()
  {
    return allumee;
  }

  public void setBordureSize(int bordureSize)
  {
     this.bordureSize = bordureSize;
     repaint();
  }

  public int getBordureSize()
  {
     return bordureSize;
  }

  public void paint(Graphics g)
  {
     super.paint(g);
     //int s = Math.min(getSize().width - 2, getSize().height - 2);
     int s1 = getSize().width - 2;
     int s2 = getSize().height - 2;

     // draw the perimeter of the button
     //g.setColor(colorLed.darker().darker().darker());
     g.setColor(Color.black);
     if (rounded)
     {
        //g.fillOval(0, 0, s, s);
        g.fillOval(0, 0, s1, s2);
     }
     else
     {
        g.fillRect(0, 0, s1, s2);
     }
     //g.fillArc(0, 0, s, s, 0, 360);
     //g.drawArc(0, 0, s, s, 0, 360);

     // paint the interior of the button
     if(!allumee)
     {
        g.setColor(colorLed.darker().darker());
     }
     else
    {
        g.setColor(colorLed);
    }
    if (rounded)
    {
       g.fillArc(bordureSize, bordureSize, s1-(bordureSize * 2), s2- (bordureSize * 2), 0, 360);
    }
    else
    {
      g.fillRect(bordureSize, bordureSize, s1-(bordureSize * 2), s2- (bordureSize * 2));
    }
  }

  /**
   * The preferred size of the button.
   */
/*
  public Dimension getPreferredSize()
  {
    return new Dimension(30, 30);
  }
*/
  /**
   * The minimum size of the button.
   */
/*
  public Dimension getMinimumSize()
  {
     return new Dimension(30, 30);
  }
*/
}